/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86187
 * Date: 2022-04-22
 * Time: 12:36
 */

//Scanner scan = new Scanner(System.in);

import java.util.Arrays;

public class TestDemo {

    /**
     * 数组的相关方法
     * Arrays:
     * toString  binarySearch  copyOf
     * copyOfRange   equals  fill  sort
     * @param args
     */

    public static void main(String[] args) {
        int[] array = {1,5,7,9,15,24,36};
        int[] array2 = {3,12,6,42,26,51,25};

        //1.toString:将数组转为字符串，返回一个字符串
        System.out.println(Arrays.toString(array2));
        System.out.println();

        //2. binarySearch:查找有序数组元素，若找到返回该元素下标
        int ret = Arrays.binarySearch(array,5);
        System.out.println("下标是："+ret);
        //该查找可以给定范围
        int ret2 = Arrays.binarySearch(array,2,5,9);
                                //在数组的2号下标处至5号下标之间查找9 注意：范围是[2,5),Java中一般都是左闭右开，
        System.out.println("下标是："+ret2);
        System.out.println();


        //3.copyOf
        int[] arr = Arrays.copyOf(array2,array2.length);
                                //要拷贝的数组，  拷贝的长度
        System.out.println(Arrays.toString(arr));

        //4.copyOfRange
        int[] arr2 = Arrays.copyOfRange(array2,1,array2.length);
                                     //要拷贝的数组， 拷贝的范围[1~array2.length)
        System.out.println(Arrays.toString(arr2));
        System.out.println();

        //5.equals：判断两个数组是否相等，相等返回true 否则返回false
        boolean flg = Arrays.equals(array,array2);
        System.out.println(flg);
        System.out.println();

        //6.fill:填充数组，无返回值
        int[] arr3 = new int[10];
        Arrays.fill(arr3,3);//将数组填充为3
        System.out.println(Arrays.toString(arr3));
        Arrays.fill(arr3,2,5,5);//将数组2号下标处至5号下标置5 -- [2,5)
        System.out.println(Arrays.toString(arr3));
        System.out.println();

        //7.sort:将数组排升序,无返回值
        Arrays.sort(array2);
        System.out.println(Arrays.toString(array2));
    }
}
